package com.example.demotool.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    /**
     @RequestMapping("test_redis")
     public String testRedis(){
     String name = stringRedisTemplate.opsForValue().get("name");
     return name;
     }
     */
    @RequestMapping("/publish")
    public String publish(){
        for(int i=1;i<=10;i++){
            stringRedisTemplate.convertAndSend("mytopic", "这是我发第"+i+"条的消息啊");
        }
        return "结束";
    }
}
